﻿@model Bricks.Site.Models.ContractFilterView
@{
    ViewBag.Title = "EngineeringImageScheduleList";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}


<script type="text/javascript">
    $(function () {
        var userType = $("#hUserType").val();
        if (userType == "0") {
            var trCommom = document.getElementById('trCommon');
            var table = trCommom.parentNode;
            table.removeChild(trCommom);
            var url = '/EngineeringImageSchedule/GetEngineeringImageScheduleList?projectID=' + $("#hProjectID").val() + '&contractType=' + encodeURI($("#ContractType").val()) + '&contractID=' + $("#hContractID").val();
            initTable(url);
        }
        else {
            var trRequest = document.getElementById('trRequest');
            var table = trRequest.parentNode;
            table.removeChild(trRequest);

            $('#ContractType').combobox({
                editable: false, panelHeight: "auto",
                valueField: "DictionaryName",
                textField: "DictionaryName",
                url: "/Dictionary/GetDictionaryByTypeTag?typeTag=ContractType",
                onLoadSuccess: function () {
                    var data = $('#ContractType').combobox('getData');
                    if (data.length > 0) {
                        $('#ContractType').combobox('select', data[0]["DictionaryName"]);
                    }
                },
                onSelect: function (record) {
                    var projectID = $("#ProjectID").combobox('getValue');
                    initContract(projectID, record.DictionaryName);
                }
            });

            $("#ProjectID").combobox({
                editable: false, panelHeight: "auto",
                valueField: 'ID',
                textField: 'ProjectName',
                url: '/ProjectInfo/ProjectInfoListForFlow',
                onLoadSuccess: function () {
                    var data = $("#ProjectID").combobox('getData');
                    if (data.length > 0) {
                        $("#ProjectID").combobox('select', data[0]["ID"]);
                    }
                },
                onSelect: function (record) {
                    var contractType = $("#ContractType").combobox('getValue');
                    initContract(record.ID, contractType);
                }
            });
        }
    });

    function initContract(projectID, contractType) {
        $("#ContractID").combobox({
            editable: false, panelHeight: "auto",
            valueField: 'ID',
            textField: 'ContractName',
            url: '/ContractInfo/ContractInfoListByProjectIDAndType?projectID=' + projectID + '&contractType=' + encodeURI(contractType),
            onLoadSuccess: function () {
                var data = $("#ContractID").combobox('getData');
                if (data.length > 0) {
                    $("#ContractID").combobox('select', data[0]["ID"]);
                }
            }
        });
    }

    function Search() {
        var projectID = $("#ProjectID").combobox('getValue');
        var contractType = $("#ContractType").combobox('getValue');
        var contractID = $("#ContractID").combobox('getValue');
        var url = '/EngineeringImageSchedule/GetEngineeringImageScheduleList?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&contractID=' + contractID;
        initTable(url);
    }

    function initTable(dataUrl) {
        $('#mainGrid').datagrid({
            url: dataUrl,
            iconCls: 'icon-bricks',
            nowrap: true,//当数据长度超出列宽时将会自动截取
            autoRowHeight: false,
            striped: true,//设置为true将交替显示行背景
            collapsible: true,
            pagination: true,
            pageSize: 20,
            remoteSort: false,
            idField: 'ID',//表明该列是一个唯一列。
            singleSelect: true,
            fitColumns: true,
            toolbar: '#toolBar',
            columns:
            [
                [
                    { title: 'ID', field: 'ID', hidden: true },
                    { title: 'Year', field: 'Year', hidden: true },
                    { title: 'Month', field: 'Month', hidden: true },
                    { title: '统计周期', field: 'StatisticalCycle', align: 'center', width: 100 },
                    { title: '申报人', field: 'RequestPersonName', align: 'center', width: 100 },
                    { title: '申请时间', field: 'RequestDateStr', align: 'center', width: 100 },
                    { title: '审批时间', field: 'LastUpdateTimeStr', align: 'center', width: 100 },
                    { title: '流程监控', field: 'ProcedureMonitor', align: 'center', width: 500 }
                ]
            ],
            onClickRow: function (rowIndex, rowData) {
                $('#btnDelete').linkbutton('enable');
                var url = '';
                var year = rowData.Year;
                year = parseInt(year) - 1;
                var userType = $("#hUserType").val();
                if (userType == "0") {
                    url = '/EngineeringImageSchedule/GetEngineeringImageScheduleDetailList?projectID=' + $("#hProjectID").val() + '&contractType=' + encodeURI($("#ContractType").val()) + '&contractID=' + $("#hContractID").val() + '&year=' + rowData.Year + '&month=' + rowData.Month + '&pid=' + rowData.ID;
                }
                else {
                    var projectID = $("#ProjectID").combobox('getValue');
                    var contractType = $("#ContractType").combobox('getValue');
                    var contractID = $("#ContractID").combobox('getValue');
                    url = '/EngineeringImageSchedule/GetEngineeringImageScheduleDetailList?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&contractID=' + contractID + '&year=' + rowData.Year + '&month=' + rowData.Month + '&pid=' + rowData.ID;
                }
                initDetailTable(url, year);
            },
            onLoadSuccess: function (rowData) {
                if (rowData.rows.length > 0) {
                    $('#mainGrid').datagrid('selectRow', 0);
                    var row = $("#mainGrid").datagrid("getSelected");
                    var userType = $("#hUserType").val();

                    var url = '';
                    var year = row.Year;
                    year = parseInt(year) - 1;
                    if (userType == "0") {
                        url = '/EngineeringImageSchedule/GetEngineeringImageScheduleDetailList?projectID=' + $("#hProjectID").val() + '&contractType=' + encodeURI($("#ContractType").val()) + '&contractID=' + $("#hContractID").val() + '&year=' + row.Year + '&month=' + row.Month + '&pid=' + row.ID;
                    }
                    else {
                        var projectID = $("#ProjectID").combobox('getValue');
                        var contractType = $("#ContractType").combobox('getValue');
                        var contractID = $("#ContractID").combobox('getValue');
                        url = '/EngineeringImageSchedule/GetEngineeringImageScheduleDetailList?projectID=' + projectID + '&contractType=' + encodeURI(contractType) + '&contractID=' + contractID + '&year=' + row.Year + '&month=' + row.Month + '&pid=' + row.ID;
                    }
                    initDetailTable(url, year);
                }
                else {
                    initDetailTable();
                }
            },
            onDblClickRow: function (rowIndex, rowData) {
                PopEngineeringImageSchedule(rowData.HandleState, rowData.ID);
            }
        });
    }

    function PopEngineeringImageSchedule(handleState, id) {
        var processType = '1';
        if (handleState == "0") {
            processType = '2';
        }
        showMyWindow("#myWindow", "", "/EngineeringImageSchedule/EngineeringImageSchedule?MenuCode=EngineeringImageSchedule&sourceType=0&processType=" + processType + "&sourceID=&engineeringImageScheduleID=" + id, 1000, 500, true, true, true);
    }

    function initDetailTable(dataUrl, year) {
        if (year == undefined)
        {
            year = 2014;
        }
        $('#detailGrid').datagrid({
            url: dataUrl,
            iconCls: 'icon-bricks',
            nowrap: true,//当数据长度超出列宽时将会自动截取
            autoRowHeight: true,
            striped: true,//设置为true将交替显示行背景
            collapsible: true,
            pagination: true,
            pageSize: 20,
            remoteSort: false,
            idField: 'ID',//表明该列是一个唯一列。
            singleSelect: true,
            fitColumns: true,
            columns:
            [
                 [
                   { title: '主要工程内容', field: '', rowspan: 2, width: 100 },
                   { title: '序号', field: '', rowspan: 2, width: 50 },
                   { title: '计算单位', field: '', rowspan: 2, width: 70 },
                   { title: '设计总工程量', field: '', rowspan: 2, width: 100 },
                   { title: '自开始建设至' + year + '年底完成工程量', field: '', rowspan: 2, width: 250 },
                   { title: '本年进度统计', field: '', colspan: 4, width: 400 },
                   { title: '自开始建设至本月底累计完成', field: '', rowspan: 2, width: 200 },
                   { title: '备 注', field: '', rowspan: 2, width: 200 }

                 ],
               [
                   { title: '本年计划完成工程量', field: '', width: 150, height: 36 },
                   { title: '本月完成工程量', field: '', width: 150, height: 36 },
                   { title: '本年累计完成工程量', field: '', width: 150, height: 36 },
                   { title: '完成年计划的百分率', field: '', width: 150, height: 36 }

               ],
               [

                    { title: '甲', field: 'EngineeringImageStatisticsItemName', align: 'center', width: 100 },
                    { title: '乙', field: 'OrderNo', align: 'center', width: 50 },
                    { title: '丙', field: 'Unit', align: 'center', width: 70 },
                    { title: '1', field: 'TotalDesignMoneyNum', align: 'center', width: 100 },
                    { title: '2', field: 'CumulativeCompletedMoneyNum', align: 'center', width: 250 },
                    { title: '3', field: 'CurrentYearPlanCompletedMoneyNum', align: 'center', width: 150 },
                    { title: '4', field: 'CurrentMonthCompletedMoneyNum', align: 'center', width: 150 },
                    { title: '5', field: 'CurrentYearCumulativeCompletedMoneyNum', align: 'center', width: 150 },
                    { title: '6', field: 'CurrentYearCumulativeCompletedYearPlanProportion', align: 'center', width: 150 },
                    { title: '7', field: 'CumulativeToCurrentMonthCompletedMoneyNum', align: 'center', width: 200 },
                    { title: '丁', field: 'Remark', align: 'center', width: 200 }
               ]
            ],
            onLoadSuccess: function (data) {
                if (data.rows.length > 1) {
                    mergeCellsByField("detailGrid", "EngineeringImageStatisticsItemName");
                }
            }
        });
    }

    var EngineeringImageScheduleList =
    {
        Add: function () {
            if ($("#hProjectID").val() == '' || $("#ContractType").val() == '' || $("#hContractID").val() == '') {
                $.messager.alert('操作提示', "项目、合同类型和标段不能为空！", 'info');
            }
            else {
                $.post("/UserMenuAction/GetUserDepartmentForFlow?menuCode=EngineeringImageScheduleList", function (userDepartment) {
                    if (userDepartment == "") {
                        showMyWindow("#myWindow", "选择机构", "/UserMenuAction/ShowOrgByUserForFlow?menuCode=EngineeringImageScheduleList", 500, 280, true, false);
                    }
                    else if (userDepartment == "**********") {
                        $.messager.alert('操作提示', '当前用户不属于任何机构，请先设置所属机构！', 'info');
                    }
                    else if (userDepartment == "++++++++++") {
                        $.messager.alert('操作提示', '当前用户的机构不属于流程申请配置机构，不能新增！', 'info');
                    }
                    else {
                        showMyWindow("#myWindow", "", '/EngineeringImageSchedule/EngineeringImageSchedule?MenuCode=EngineeringImageSchedule&sourceType=1&processType=&sourceID=&lastUpdateUserDepartment=' + userDepartment + '&projectID=' + $("#hProjectID").val() + '&contractType=' + encodeURI($("#ContractType").val()) + '&contractID=' + $("#hContractID").val(), 1000, 500, true, true, true);
                    }
                });
            }
        },

        Delete: function () {
            var row = $("#mainGrid").datagrid("getSelected");
            $.messager.confirm('操作提示', "确认删除统计周期【" + row.StatisticalCycle + "】吗？", function (r) {
                if (r) {
                    $.post('/EngineeringImageSchedule/Delete?engineeringImageScheduleID=' + row.ID, function (res) {
                        if (res == "Success") {
                            var url = '/EngineeringImageSchedule/EngineeringImageScheduleList?projectID=' + $("#hProjectID").val() + '&contractType=' + encodeURI($("#ContractType").val()) + '&contractID=' + $("#hContractID").val();
                            initTable(url);
                            $.messager.alert('操作提示', '删除成功!', 'info');
                        }
                        else {
                            if (res == "") {
                                $.messager.alert('操作提示', '删除失败!请查看该数据与其他模块下的信息的关联，或联系管理员。', 'info');
                            }
                            else {
                                $.messager.alert('操作提示', res, 'info');
                            }
                        }
                    });
                }
            });
        }
    }

    function cancelPopWindow(handleState) {
        if (handleState == "0") {
            var url = '/EngineeringImageSchedule/GetEngineeringImageScheduleList?projectID=' + $("#hProjectID").val() + '&contractType=' + encodeURI($("#ContractType").val()) + '&contractID=' + $("#hContractID").val();
            initTable(url);
        }
        colseMyWindow("#myWindow");
    }

    function CloseWindow(data) {
        colseMyWindow("#myWindow");
        var url = '/EngineeringImageSchedule/GetEngineeringImageScheduleList?projectID=' + $("#hProjectID").val() + '&contractType=' + encodeURI($("#ContractType").val()) + '&contractID=' + $("#hContractID").val();
        initTable(url);
        $.EasyuiSlide(data);
    }
</script>

<div class="easyui-layout" style="height:740px;width:100%;">
    <input type="hidden" id="hProjectID" name="ProjectID" value="@Model.ProjectID" />
    <input type="hidden" id="hContractID" name="ContractID" value="@Model.ContractID" />
    <input type="hidden" id="hUserType" name="UserType" value="@Model.UserType" />
    <div data-options="region:'north'" style="height:35px;">
        <table style="margin-top: 5px">
            <tr id="trCommon">
                <td style="width: 95px; text-align: center">项目名称</td>
                <td>
                    <input id="ProjectID" name="ProjectID" class="easyui-combobox" style="width: 180px;" />
                </td>
                <td style="width: 95px; text-align: center">合同类型</td>
                <td>
                    <input id="ContractType" name="ContractType" class="easyui-combobox" style="width: 180px;" />
                </td>
                <td style="width: 95px; text-align: center">标段名称</td>
                <td colspan="3">
                    <input id="ContractID" name="ContractID" class="easyui-combobox" style="width: 450px;" />
                </td>
                <td>
                    <a href="#" id="btnSearch" class="easyui-linkbutton" data-options="plain:true" onclick="Search();">查看</a>
                </td>
            </tr>
            <tr id="trRequest">
                <td style="width: 95px; text-align: center">项目名称</td>
                <td>
                    <input name="ProjectName" id="ProjectName" class="easyui-textbox" data-options="required:true" value="@Model.ProjectName" style="width: 175px;" readonly />
                </td>
                <td style="width: 95px; text-align: center">合同类型</td>
                <td>
                    <input name="ContractType" id="ContractType" class="easyui-textbox" data-options="required:true" value="@Model.ContractType" style="width: 175px;" readonly />
                </td>
                <td style="width: 95px; text-align: center">标段名称</td>
                <td>
                    <input name="ContractName" id="ContractName" class="easyui-textbox" data-options="required:true" value="@Model.ContractName" style="width: 175px;" readonly />
                </td>
            </tr>
        </table>
    </div>
    <div data-options="region:'center'">
        <div class="easyui-layout" fit="true">
            <div data-options="region:'north'" style="height:250px;">
                <table id="mainGrid" fit="true"></table>
                <div id="toolBar">
                    @Html.Raw(ViewBag.ToolBarInfo)
                </div>
            </div>
            <div data-options="region:'center'">
                <table id="detailGrid" fit="true"></table>
            </div>
        </div>
    </div>
</div>
